package com.yx.yinshanjinniu.utils;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.meiqia.core.callback.OnInitCallback;
import com.meiqia.meiqiasdk.util.MQConfig;
import com.meiqia.meiqiasdk.util.MQIntentBuilder;

import java.util.HashMap;

public class CustomerUtil {//TODO 替换成智齿客服

    public static void customerService(final Context mContext) {
        String uid = DataUtils.getUserId(mContext);
        if (uid.equals("0")) {
            uid = "";
        } else {
            uid = "银山金牛uid-" + uid;
        }
        String uName;
        if (!DataUtils.isLogin(mContext)) {
            uName = "银山金牛游客";
        } else {
            uName = "银山金牛-" + DataUtils.getNickName(mContext);
        }
        String mobile = DataUtils.getMobile(mContext);

        String meiqiaKey = "aede9a88d49d3b1bd11a68e09e0de85c";
        MQConfig.init(mContext, meiqiaKey, new OnInitCallback() {
            @Override
            public void onSuccess(String clientId) {
//                Toast.makeText(mContext, "init success", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onFailure(int code, String message) {
                Toast.makeText(mContext, "int failure message = " + message, Toast.LENGTH_SHORT).show();
            }
        });

        HashMap<String, String> clientInfo = new HashMap<>();
        clientInfo.put("name", uName);
        clientInfo.put("tel", mobile);
        clientInfo.put("comment", uid);
        Intent intent = new MQIntentBuilder(mContext)
                .setCustomizedId(DataUtils.getDeviceId(mContext))
                .setClientInfo(clientInfo) // 设置顾客信息 PS: 这个接口只会生效一次,如果需要更新顾客信息,需要调用更新接口
                .updateClientInfo(clientInfo) // 更新顾客信息 PS: 如果客服在工作台更改了顾客信息，更新接口会覆盖之前的内容
                .build();
        mContext.startActivity(intent);


    }
}
